package com.jhy.study2.singleton;


/**
 * @author: robert
 * @description: 基于懒汉模式的线程问题
 * @date: 2021/8/22 16:17
 * @return
 */
//解决方式一：基于volatile 关键字(禁止重排序，来保证线程安全的延迟初始化)
public class SingletonClass3 {
    private static volatile SingletonClass3 obj = null;
    private SingletonClass3(){}

    public static SingletonClass3 getInstance(){
        if(obj == null){
            synchronized (SingletonClass3.class){
                if(obj == null){
                    obj = new SingletonClass3();
                }
            }

        }
        return obj;
    }


}
